//
//  ViewController.m
//  collectionTest
//
//  Created by linyr on 15/9/19.
//  Copyright (c) 2015年 away Lin. All rights reserved.
//

#import "customCell.h"
#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) NSArray *data;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _data = @[@"Hey", @"this", @"is", @"extremelyextremely", @"fun", @"but", @"LONGER HUMONGOUS", @"WORDS!", @"keep", @"going", @"Extending into", @"line 3"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [_data count];
}

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    customCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"customCell" forIndexPath:indexPath];
    //cell.backgroundColor = [UIColor grayColor];
    cell.label.text = _data[indexPath.row];
    return cell;
    
    
}


- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size =  [(NSString*)[_data objectAtIndex:indexPath.row] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18.0f]}];
    size.height = 40;
    size.width = size.width += 16;
    
    
    return size;
}

@end
